package com.ztgf.commodity.service;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.BeanUtils;

import javax.annotation.Resource;

import com.ztgf.commodity.common.config.YmlConfig;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.ztgf.commodity.mapper.CommodityParamValueMapper;
import com.ztgf.commodity.models.service.ICommodityParamValueService;
import com.ztgf.commodity.models.bo.CommodityParamValueSaveBO;
import com.ztgf.commodity.models.dto.CommodityParamValueDTO;

import java.util.List;

/**
 * 商品参数值表控制器
 *
 * @author chenyu.wang
 * @Date 2020-06-15 10:13:11
 */
@DubboService
public class CommodityParamValueServiceImpl extends ServiceImpl<CommodityParamValueMapper, CommodityParamValueDTO> implements ICommodityParamValueService {

    @Resource
    private YmlConfig ymlConfig;

    @Override
    public boolean add(CommodityParamValueSaveBO saveBO) {
        CommodityParamValueDTO dto = new CommodityParamValueDTO();
        BeanUtils.copyProperties(saveBO, dto);
        Long id = ymlConfig.getPkId();
        dto.setId(id);
        return this.insert(dto);
    }

    @Override
    public List<CommodityParamValueDTO> queryListByParamId(Long paramId) {
        Wrapper<CommodityParamValueDTO> wrapper = new EntityWrapper<>();
        wrapper.eq("param_id", paramId);
        return this.selectList(wrapper);
    }
}
